package com.news.servlet;

import com.news.db.OpDB;
import com.news.model.News;
import com.news.model.Person;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 修改新闻人物时回显数据
 */
@WebServlet("/findidp")
public class FindPersonServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doPost(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //1.获取数据
        String id = req.getParameter("id");
        int i = Integer.parseInt(id);
        //2.调用dao方法
        OpDB opdb = new OpDB();
        Person person = opdb.OpGetPerson(i);
        //3.存到request中
        req.setAttribute("person",person);
        //4.转发到IndexTemp.jsp
        req.getRequestDispatcher("/admin/IndexTemp.jsp?mainPage=updPerson").forward(req,resp);
    }
}
